//
//  ECUICVCell_HomeCategory.m
//  EduCourse
//
//  Created by yanyan on 2017/8/9.
//  Copyright © 2017年 yanyan. All rights reserved.
//

#import "ECUICVCell_HomeCategory.h"

@implementation ECUICVCell_HomeCategory
-(void)addSubviews
{
    [super addSubviews];
    UIView *view = [[UIView alloc]init];
    view.userInteractionEnabled = YES;
    [self.contentView addSubview:view];
    _imageView = [[UIImageView alloc]init];
    _imageView.userInteractionEnabled = YES;
    _imageView.contentMode = UIViewContentModeScaleAspectFit;
    [view addSubview:_imageView];
    _titleView = [[UILabel alloc]init];
    _titleView.font = [UIFont systemFontOfSize:11 * kPercentage];
    _titleView.textColor = [UIColor colorWithHexString:@"#293039"];
    [view addSubview:_titleView];
    WeakSelf(weakSelf);
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.contentView.mas_centerX);
        make.centerY.equalTo(weakSelf.contentView.mas_centerY);
    }];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_top);
        make.centerX.equalTo(view.mas_centerX);
        make.height.equalTo(@(20 * kPercentage));
        make.width.equalTo(@(20 * kPercentage * 1.156));
    }];
    [_titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.imageView.mas_bottom).offset(5 * kPercentage);
        make.centerX.equalTo(view.mas_centerX);
        make.bottom.equalTo(view.mas_bottom);
    }];
}

- (void)setObject:(id)object
{
    [super setObject:object];


    if ([object valueForKey:@"object"]) {
        id obj = [object valueForKey:@"object"];
        _titleView.text = [obj valueForKey:@"title"];
        if ([obj isKindOfClass:[PrimaryCategoryModel class]]) {
            PrimaryCategoryModel *mo = obj;
            if (mo.iconURLString) {
                [self.imageView sd_setImageWithURL:[NSURL URLWithString:mo.iconURLString] placeholderImage:[UIImage imageNamed:[object valueForKey:@"brief"]]];
                return;
            }
        }
            [self.imageView setImage:[UIImage imageNamed:[object valueForKey:@"brief"]]];

    } else {
        _titleView.text = [object valueForKey:@"name"];
        [self.imageView setImage:[UIImage imageNamed:[object valueForKey:@"brief"]]];

    }
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
